//
//  TMGSaleGoldViewController.m
//  TMGold
//
//  Created by Mac on 2017/12/12.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGBuyGoldViewController.h"
#import "NSCalendar+STCalendarTool.h"
#import "NSCalendar+STCalendarTool.h"
@interface TMGBuyGoldViewController ()<UITextFieldDelegate>
@property(nonatomic, strong) UITextField                     *textFiled;
@property(nonatomic, strong) NSArray                        *dataSouce;
@property(nonatomic, strong) STButton                     *desButton;
@property(nonatomic, strong) NSString                     *trade_type;//1买金3买钱
@property(nonatomic, strong) NSString                     *start;//结束日子
@property(nonatomic, strong) NSString                     *end;//开始日子
@property(nonatomic, strong) TMGProductDetailModel                     *detailModel;
@end

@implementation TMGBuyGoldViewController
- (instancetype)initWithGoldType:(TMGBuyGoldType)type{
    if (self == [super init]) {
        self.type = type;
    }
    return self;
}
- (void)setModel:(TMGProductDetailModel *)model{
    _model = model;
    self.title = model.name;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.start = @"";
    self.end = @"";
    [self sendGoodDetailReqeust];
    [self configDataSouce];
    [self configSubView];
    //[self configFooterView];
    [self configBottomView];
    [self addNotifacations];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"提示111"]];
    // Do any additional setup after loading the view.
}
#pragma mark --Notifacation
- (void)addNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(uitextFieldTextDidChangeNotification:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSArray * array = [self.textFiled.text componentsSeparatedByString:@"."];
    NSString * normal = @"";
    if (array.count > 1) {
        normal = array.lastObject;
    }
    if (normal.length >= 2 && string.length) {
        return NO;
    }
    return YES;
}
- (void)uitextFieldTextDidChangeNotification:(NSNotification*)notify{
    
    if (notify.object == self.textFiled) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            if (self.model.cate.integerValue == 1) {
//                if (![self.textFiled.text isEqualToString:@"1"]) {
//                    [SVProgressHUD showInfoWithStatus:@"新手特权金只能购买1克哦"];
//                    self.textFiled.text = @"1";
//                    
//                }
//            }
            CGFloat ke = [self.textFiled.text floatValue];
            CGFloat money = ke * self.model.price.floatValue;
            STTableEasyModel * model = self.dataSouce[1];
            if ([model.textString isEqualToString:@"预计金额"]) {
                NSString * rate = self.model.year_rate_from;
                CGFloat biginMoney = money * rate.floatValue/100;
                NSString * beginString = [NSString stringWithFormat:@"%0.2f(元)",biginMoney];
                 model.detailString = beginString;
               
                if (self.model.year_rate_to.floatValue > 0.1) {
                    rate = self.model.year_rate_to;
                    CGFloat end = money * rate.floatValue/100;
                    model.detailString = [NSString stringWithFormat:@"%0@~%0.2f(元)",beginString,end];
                }
                
               
                [self.tableView reloadData];
            }

        });

    }
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)configDataSouce{
    self.textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0.66*UIScreenWidth, 44)];
    self.textFiled.placeholder = @"输入购买重量";
    self.textFiled.keyboardType = UIKeyboardTypeDecimalPad;
    self.textFiled.delegate = self;
    NSString * money = @"0.00";
    if (self.model.cate.integerValue == 1) {
        self.textFiled.text = @"1";
        self.textFiled.userInteractionEnabled = NO;
        money = @"248(元)";
    }
    NSString * rate = self.model.year_rate_from;
    if (self.model.year_rate_to.floatValue > 0.1) {
        rate = [NSString stringWithFormat:@"%@~%@",self.model.year_rate_from,self.model.year_rate_to];
    }
    rate = [NSString stringWithFormat:@"%@%%",rate];
    
    self.dataSouce = @[
                       [[STTableEasyModel alloc] initWithTextString:@"购买克重" accessoryView:self.textFiled],
                       [[STTableEasyModel alloc] initWithTextString:@"预计金额" detailString:money],
                       [[STTableEasyModel alloc] initWithTextString:@"利率"
                                                       detailString:rate],
                       [[STTableEasyModel alloc] initWithTextString:@"计息日"
                                                       detailString:[NSCalendar st_nextDayDate:[NSDate st_localCurrentDate]].st_yyyyMMddByLineWithDate]];
    self.trade_type = @"1";//买金
    self.start = [NSCalendar st_nextDayDate:[NSDate st_localCurrentDate]].st_yyyyMMddByLineWithDate;
    if (self.model.day_number.integerValue > 0) {
        NSInteger days =  self.model.day_number.integerValue;
        if (self.model.cate.integerValue == 6) {
            days = 30 * self.model.day_number.integerValue;
        }
        NSDate * date = [NSCalendar st_nextDayDate:[NSDate st_localCurrentDate]];
        for (NSInteger i =0 ; i < days; i ++) {
            date = [NSCalendar st_nextDayDate:date];
        }
        NSMutableArray * array = [self.dataSouce mutableCopy];
        STTableEasyModel * model =  [[STTableEasyModel alloc] initWithTextString:@"到期日"
                                                                   detailString:date.st_yyyyMMddByLineWithDate];
        [array addObject:model];
        self.end =  date.st_yyyyMMddByLineWithDate;
        self.dataSouce = [array copy];
       
    }
    if (self.model.cate.integerValue == 4 || self.model.cate.integerValue == 5|| self.model.cate.integerValue == 6) {
        //买钱
        self.trade_type = @"3";
        NSString * buyLimit = [NSString stringWithFormat:@"%@元起购",
                               @(self.model.buy_start.integerValue)];
        self.textFiled.placeholder = buyLimit;
        self.dataSouce = @[
                           [[STTableEasyModel alloc] initWithTextString:@"金额" accessoryView:self.textFiled],
                           [[STTableEasyModel alloc] initWithTextString:@"计息日"
                                                           detailString:[NSCalendar st_nextDayDate:[NSDate st_localCurrentDate]].st_yyyyMMddByLineWithDate]];
    }
    [self.tableView reloadData];
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    header.backgroundColor = [UIColor whiteColor];
    
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 193)];
    bannerImageView.image = [UIImage imageNamed:@"wdebanner"];
    bannerImageView.userInteractionEnabled = YES;
    [header addSubview:bannerImageView];
    

//    NSString * rate = self.detailModel.year_rate_from;
//    if (self.detailModel.year_rate_to.floatValue > 0.1) {
//        rate = [NSString stringWithFormat:@"%@~%@",self.detailModel.year_rate_from,self.detailModel.year_rate_to];
//    }
//    rate = [NSString stringWithFormat:@"%@%%",rate];
    
   

    
    if (self.model.cate.integerValue == 4 || self.model.cate.integerValue == 5 || self.model.cate.integerValue == 6) {
        NSString * rate = self.model.year_rate_from;
        if (self.model.year_rate_to.floatValue > 0.1) {
            rate = [NSString stringWithFormat:@"%@~%@",self.model.year_rate_from,self.model.year_rate_to];
        }
        
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 10, 200, 80)
                                                         text:[NSString stringWithFormat:@"%@%%\n预期复合黄金收益率",rate]
                                                    textColor:[UIColor whiteColor]
                                                         font:26
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        titleLable.centerX = UIScreenWidth / 2;
        titleLable.attributedText = [titleLable.text st_convertAttributeStringWithKeyWord:@"预期复合黄金收益率"
                                                                               attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor whiteColor]}];
        [bannerImageView addSubview:titleLable];
    }else{
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 10, 200, 80)
                                                         text:[NSString stringWithFormat:@"%@\n实时金价(元/克)",
                                                               self.model.price]
                                                    textColor:[UIColor whiteColor]
                                                         font:26
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        titleLable.centerX = UIScreenWidth / 2;
        titleLable.attributedText = [titleLable.text st_convertAttributeStringWithKeyWord:@"实时金价(元/克)" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
        [bannerImageView addSubview:titleLable];
        if (self.model.cate.integerValue == 1) {
            titleLable.text = [NSString stringWithFormat:@"%@\n活动金价(元/克)",
                               @"248"];
            titleLable.attributedText = [titleLable.text st_convertAttributeStringWithKeyWord:@"活动金价(元/克)" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
        }else{
            [TMUtils fetchCurrentGoldPrice:^(TMCurrentColdModel *currentModel) {
                
                if (currentModel) {
                    self.model.price = currentModel.latestpri;
                    titleLable.text = [NSString stringWithFormat:@"%@\n实时金价(元/克)",
                                       self.model.price];
                    titleLable.attributedText = [titleLable.text st_convertAttributeStringWithKeyWord:@"实时金价(元/克)" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
                }
            }];
        }
    }
    


    if (self.type == TMGBuyGoldTypeGreenHand) {
        bannerImageView.image = [UIImage new];
        bannerImageView.backgroundColor = TM_orangeColor;
        bannerImageView.height = 100;
    }
    
    
    STLabel * saleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, bannerImageView.bottom, UIScreenWidth, 60)
                                                    text:@"账户余额0.00元"
                                               textColor:TM_firstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    saleLable.backgroundColor = [UIColor whiteColor];
    [header addSubview:saleLable];

    
    [TMUtils fetchPersonnalInfo:^(TMGUserModel *user) {
        saleLable.text = [NSString stringWithFormat:@"账户余额%@元",
                          user.money];
        saleLable.attributedText = [saleLable.text st_convertAttributeStringWithKeyWord:user.money attributes:@{NSForegroundColorAttributeName:TM_orangeColor}];
    }];
    header.height = saleLable.bottom;
    //头部橘色
    UIView * headers = [[UIView alloc] initWithFrame:CGRectMake(0, -header.height, UIScreenWidth, 2 * header.height)];
    headers.backgroundColor = TM_orangeColor;
    [header insertSubview:headers atIndex:0];
    
    self.tableView.tableHeaderView = header;
    
}
- (void)configBottomView{

    
    __weak typeof(self) weakSelf =  self;
    STButton * nextButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth / 1, 49)
                                                      title:@"确定下单"
                                                 titleColor:FlatWhite
                                                  titleFont:15
                                               cornerRadius:0
                                            backgroundColor:TM_orangeColor
                                            backgroundImage:nil
                                                      image:nil];
    nextButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [nextButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedNextButton];
    }];
    nextButton.top = [TMUtils tabBarTop];
    [self.view addSubview:nextButton];
    
    
    STButton * desButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                     title:@""
                                                titleColor:TM_secendTextColor
                                                 titleFont:13
                                              cornerRadius:0
                                           backgroundColor:self.tableView.backgroundColor
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"icon_选中"]];
    [desButton setImage:[UIImage imageNamed:@"icon_未选中"] forState:UIControlStateSelected];
    self.desButton = desButton;
    [desButton setClicAction:^(UIButton *sender) {
        sender.selected = !sender.selected;
    }];
    desButton.selected = YES;
    desButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.view addSubview:desButton];
    desButton.bottom = nextButton.top;
    

    STButton *titleButton = [[STButton alloc] initWithFrame:CGRectMake(desButton.right, 0, UIScreenWidth, 44)
                                                     title:@"我已经认真阅读并同意黄金口袋购买合同"
                                                titleColor:TM_secendTextColor
                                                 titleFont:13
                                              cornerRadius:0
                                           backgroundColor:self.tableView.backgroundColor
                                           backgroundImage:nil
                                                     image:nil];
    [titleButton setAttributedTitle:[titleButton.currentTitle st_convertAttributeStringWithKeyWord:@"黄金口袋购买合同" attributes:@{NSForegroundColorAttributeName:TM_orangeColor}] forState:UIControlStateNormal];
    [titleButton setClicAction:^(UIButton *sender) {
        
        NSString * url = [NSString stringWithFormat:@"http://jshjkd.com/gold/public/home/web/contract?cate=%@",
                          weakSelf.model.cate];
        STWebViewController * webvc = [[STWebViewController alloc] initWithUrl:url];
        webvc.progressBackgroundColor = [UIColor whiteColor];
        webvc.progressTintColor = TM_orangeColor;
        webvc.forceTitle = weakSelf.model.name;
        [weakSelf.navigationController pushViewController:webvc animated:YES];
    }];
    titleButton.bottom = nextButton.top;
    [self.view addSubview:titleButton];
    

}
- (void)configFooterView{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30 , 44)
                                                        title:@"投资小提示 点击查看"
                                                   titleColor:TM_firstTextColor
                                                    titleFont:14
                                                 cornerRadius:10
                                              backgroundColor:nil
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setAttributedTitle:[confimButton.currentTitle st_convertAttributeStringWithKeyWord:@"点击查看" attributes:@{NSForegroundColorAttributeName:TM_orangeColor}] forState:UIControlStateNormal];
    
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedAlertButton];
    }];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [footer addSubview:confimButton];
    
    self.tableView.tableFooterView = footer;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.textColor = UIColorFromRGBA(0x333333);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.textColor = [UIColor blackColor];
    
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    cell.textLabel.text = model.textString;
    cell.accessoryType = UITableViewCellAccessoryNone;
    if (model.accessoryView) {
        cell.accessoryView = model.accessoryView;
    }else{
        cell.detailTextLabel.text = model.detailString;
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{
    
    TMGNotePresentViewController * vc = [TMGNotePresentViewController new];
    NSString * string = @"1、预计计息日为买入后的第二天。\n2、每人每日累计可买入1000克，卖出1000克。\n3、买入无任何手续费，卖出手续费为0.3元/克。\n4、黄金口袋买卖金线上交易时间段: 每周周一至周五早9: 00-2: 30(次日)。\n5、由于金价实时变动，实际可购买克重可能与预计克重有所偏差。\n";
    vc.note = string;
    vc.titleString = @"小提示";
    [self presentViewController:vc animated:NO completion:nil];

}
- (void)onSelectedAlertButton{

}
//确定下单
- (void)onSelectedNextButton{
    CGFloat money = self.textFiled.text.floatValue * self.model.price.floatValue;
    if (self.desButton.selected) {
        [SVProgressHUD showErrorWithStatus:@"请仔细阅读黄金口袋购买合同并且同意"];
        return;
    }
    if (!self.textFiled.text.length) {
        STTableEasyModel *model = self.dataSouce.firstObject;
        if ([model.textString containsString:@"金额"]) {
            [SVProgressHUD showErrorWithStatus:@"您还没有输入金额"];
        }else{
            [SVProgressHUD showErrorWithStatus:@"您还没有输入克重"];
        }
        
        return;
    }
    if (self.textFiled.text.floatValue < self.model.buy_start.floatValue) {
        [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@起购",@(self.model.buy_start.integerValue)]];
        return;
    }
    
    TMGMakeOrderViewController * vc = [TMGMakeOrderViewController new];
    vc.trade_type = self.trade_type;
    vc.model = self.model;
    vc.money = self.textFiled.text;
    if (self.model.cate.integerValue == 1) {
        vc.money = @"248";
        vc.ke = @"1";
    }
    vc.end = self.end;
    
    [TMUtils fecthOnSaleRequestWithGoodTitle:self.title money:vc.money handle:^(NSArray *array) {
        [SVProgressHUD dismiss];
        if (!array.count) {
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [self showAlertTitle:@"检测到您还有未使用的优惠券，请问需要使用吗" message:@"" leftTitle:@"不了" rightTitle:@"去选择" block:^(NSString *name) {
                if ([name isEqualToString:@"去选择"]) {
                    TMGChoseDisCountViewController * discountVC  = [TMGChoseDisCountViewController new];
                    discountVC.dataSouce = array;
                    [discountVC setChosedHandle:^(TMGDiscountModel *model) {
                        if (model) {
                            vc.m_vid = model.discountID.description;
                            [self.navigationController pushViewController:vc animated:YES];
                        }else{
                            [self.navigationController pushViewController:vc animated:YES];
                        }
                        
                    }];
                    [self.navigationController pushViewController:discountVC animated:YES];
                }else{
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
            }];
        }
    }];


}
#pragma mark --NetWork Method
- (void)sendCreateOrderRequest{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/order/addOrderBuy"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if ([STUserManger defult].token.length) {
        [dic setObject:[STUserManger defult].token forKey:@"token"];
    }
    [dic setObject:self.model.goodID forKey:@"gid"];
    [dic setObject:self.model.cate forKey:@"cate"];
    [dic setObject:self.model.year_rate_from forKey:@"year_rate"];
    [dic setObject:self.start forKey:@"start"];
    [dic setObject:self.end forKey:@"end"];
    [dic setObject:self.trade_type forKey:@"trade_type"];
    NSDate * date = [NSDate st_localCurrentDate];
    NSString * today = date.st_yyyyMMddByLineWithDate;
     [dic setObject:today forKey:@"start"];
    for (NSInteger i =0; i < 90; i ++ ) {
        date = [NSCalendar st_nextDayDate:date];
    }
    if (self.textFiled.text.length) {
        [dic setObject:self.textFiled.text forKey:@"goods_number"];
    }

    
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];

//                                                 [SVProgressHUD showSuccessWithStatus:@"下单成功"];
                                                 NSNumber * oid =responseObject[@"data"][@"oid"];
                                                 [TMUtils fetchPersonnalInfo:^(TMGUserModel *user) {
                                                     [SVProgressHUD dismiss];
                                                     if (user.is_verify) {
                                                         [self presentInputPwdViewControllerWithOrder:oid.description];
                                                     }else{
                                                         [SVProgressHUD showErrorWithStatus:@"请先实名认证"];
                                                     }
                                                 }];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
- (void)presentInputPwdViewControllerWithOrder:(NSString*)order{
    LBPassWordPresentViewController * vc = [LBPassWordPresentViewController new];
    [vc setPwdDidEdited:^(LBPassWordPresentViewController *passVC ,NSString *inputPwd) {
        [self sendBuyRequestWithOid:order pwd:inputPwd handle:^(NSString *errorDesc) {
            if (!errorDesc.length) {
                [SVProgressHUD showSuccessWithStatus:@"购买成功"];
                [passVC dismissWithHandle:^{
                    [self.navigationController popViewControllerAnimated:YES];
                }];
            }else{
                if ([errorDesc isEqualToString:@"交易密码不正确!"]) {
                    passVC.alertLable.text = @"密码错误";
                    passVC.alertLable.hidden = NO;
                    [passVC rightLablebackAnimation];
                }else{
                    [SVProgressHUD showErrorWithStatus:errorDesc];
                }

            }
        }];
    }];
    [self presentViewController:vc animated:NO completion:nil];
}
- (void)sendBuyRequestWithOid:(NSString*)oid pwd:(NSString*)pwd handle:(void(^)(NSString * errorDesc))handle{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/money/balancePay"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    if ([STUserManger defult].token.length) {
        [dic setObject:[STUserManger defult].token forKey:@"token"];
    }
    if (oid.length) {
        [dic setObject:oid forKey:@"oid"];
    }
    if (pwd.length) {
        [dic setObject:pwd forKey:@"pay_password"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 if (handle) {
                                                     handle(@"");
                                                 }
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 if (handle) {
                                                     handle(error.desc);
                                                 }
                                             }];
}

- (void)sendGoodDetailReqeust{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/goods/getGoodsDetails"];
    //    if ([STUserManger defult].userID.length) {
    //        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    //    }
    //    if ([STUserManger defult].token.length) {
    //        [dic setObject:[STUserManger defult].token forKey:@"token"];
    //    }
    if (self.model.goodID.description.length) {
        [dic setObject:self.model.goodID forKey:@"gid"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
//                                                 NSDictionary * dataDic =  responseObject[@"data"];
//                                                 //NSLog(@"json = %@",dataDic.mj_JSONString);
//                                                 self.detailModel = [TMGProductDetailModel mj_objectWithKeyValues:dataDic];
//                                                 self.detailModel.cate = self.model.cate.description;

                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}

@end

